<?php
/**
 * LoginAction.class.php    管理员登陆操作类
 *
 * @author                  mashanling(msl-138@163.com)
 * @date                    2012-06-25 15:57:05
 * @last modify             2012-12-12 08:29:38 by mashanling
 */

!defined('ROOT') && exit('Access Denied');

class LoginAction extends CommonAction {
    protected $auto_check_priv = false;//是否自动检测权限

	/**
     * 管理员登陆
     *
     * @author       mashanling(msl-138@163.com)
     * @date         2012-07-05 10:44:49
     * @last modify  2012-12-12 08:30:18 by mashanling
     *
     * @return void 无返回值
     */
    function index() {
        $css_file  = $this->loadTimeScript('START_TIME');
        $css_file .= css('extjs/resources/css/ext-all-gray.css,extjs/resources/css/ext-patch.css', IMGCACHE_JS);
        $css_file .= css('app.css');
        $js_file   = $this->loadTimeScript('LOAD_CSS_TIME');
        $js_file  .= js('');
        $js_file  .= $this->loadTimeScript('LOAD_EXT_TIME');
        $js_file  .= js('System.js,lang/' . C('DEFAULT_LANG') . '.js' . (C('DEFAULT_LANG') != 'en' ? ',lang/ext-lang-' . C('DEFAULT_LANG') . '.js' : ''), false, '/static/js/');

        if (IS_LOCAL) {
            $js_file .= js('util/common.js,util/App.Field.js,ux/App.ux.Form.js,controller/App.controller.Common.js,controller/App.controller.Login.js', false, IMGCACHE_JS . 'app/');
        }
        else {
            $js_file .= js('common.pack.js,App.controller.Common.pack.js,App.controller.Login.pack.js', false, IMGCACHE_JS . 'app/pack/');
        }

        $js_file  .= $this->loadTimeScript('LOAD_JS_TIME');

        include(C('TEMPLATE_NAME'));
    }

    /**
     * 登陆操作
     *
     * @author       mashanling
     * @date         2012-07-02 11:16:12
     * @last modify  2012-09-11 08:18:33 by mashanling
     *
     * @return void 无返回值
     */
    function login() {
        $result = $this->model->checkCreate();

        if ($result === true) {
            $this->admin_info = true;//设为true，以记录css及js加载时间记录 by mashanling on 2012-09-11 08:18:22
            $this->logLoadTime()->ajaxReturn(true);
        }
        else {
            $this->ajaxReturn(false, str_replace('<br />', ', ', $result));
        }
    }

    /**
     * 退出登陆
     *
     * @author       mashanling
     * @date         21:49 2012-7-7
     * @last modify  21:49 2012-7-7 by mashanling
     *
     * @return void 无返回值
     */
    function logout() {
        session($this->admin_session_key, null);
        $this->redirect('login');
    }

    /**
     * 验证码
     *
     * @author       mashanling
     * @date         2012-07-02 11:14:30
     * @last modify  2012-07-5 10:38:27 by mashanling
     *
     * @return void 无返回值
     */
    function verifyCode() {
        Image::buildVerifyImage();
    }
}